{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src='{% static 'jquery-1.2.6.js' %}'></script>
</head>
<body>
<table border=1px style="margin: 0 auto">
    <tr>
        <td>选择</td>
        <td>编号</td>
        <td>姓名</td>
        <td>班级</td>
        <td>操作</td>
    </tr>
    {% for stu in stus %}
        <tr>
            <td><input type="checkbox" name="itme" value="{{ stu.id }}"></td>
            <td>{{ forloop.counter }}</td>
            <td>{{ stu.sname }}</td>
            <td>{{ stu.clazz.cname }}</td>
            <td><a href="{% url 'delete' id=stu.id %}">删除</a></td>
            <td><a href="{% url 'update'  sid=stu.id %}">修改</a></td>
        </tr>
    {% endfor %}
    <tr>
        <td><a href="{% url 'deleteall' %}" onclick="a()">批量删除</a></td>
    </tr>
    <tr>
        <td><a href="/add/" style="margin: 0 auto">增加</a></td>
    </tr>
</table>
<script>
    window.onload = function f() {
        alert('欢迎' + "{{ user }}")
        return false;
    }
</script>
<script>
    function a() {
        var list = []
        var ones = document.getElementsByName('itme')
        for (var i = 0; i < ones.length; i++) {
            if (ones[i].checked === true) {
                list.push(ones[i].value) //将ones[i]的value给list
            }
        }
            if (list.length !== 0) {
                $.ajax({
                    url: '{% url 'deleteall' %}',
                    contenType: 'application/json',
                    type: 'POST',
                    traditional: true, //传过来的值是多个的话,与要加这个
                    async: false,
                    data: ({
                        'val': list
                    }),
                    success: function () {
                        alert('删除成功')
                    },
                    error: function () {
                        alert('删除失败')
                    }
                })
            } else {
                var v = '请选择选项'
                alert(v)
            }

    }
</script>
{#<script>#}
{#    function a() {#}
{#        var list = []#}
{#        var ald = document.getElementsByName('itme')#}
{#        for (var i = 0; i < ald.length; i++) {#}
{#            if (ald[i].checked === true) {#}
{#                list.push(ald[i].value)#}
{#            }#}
{#        }#}
{#        if (list.length !== 0) {#}
{#            $.ajax({#}
{#                url: '{% url 'deleteall' %}',#}
{#                contenType: 'application/json',#}
{#                type: 'POST',#}
{#                traditional: true,#}
{#                async: false,#}
{#                data: ({#}
{#                    'val': list#}
{#                }),#}
{#                success: function () {#}
{#                    alert('删除成功')#}
{#                },#}
{#                error: function () {#}
{#                    alert('删除失败')#}
{#                }#}
{#            })#}
{#            }#}
{#        else {#}
{#            var error_m = "请选择数据";#}
{#            alert(error_m);#}
{#        }#}
{##}
{#    }#}
{#</script>#}

</body>
</html>